/**
 * Created by Rossy1 on 2018/4/27.
 */
document.documentElement.style.fontSize = document.documentElement.clientWidth / 3.75 + "px"; //兼容处理

//根据uid查询作品
function getWorks(uid) {
    $.ajax({
        type: "GET",
        url: "http://14.119.109.232:30666/center/wechat/",
        data: {
            cmd: "UserDetail",
            uid: uid
        },
        success: function (res) {
            console.log(res)
            $("#nums0").text(res.fans); //粉丝
            $("#nums1").text(res.follow); //关注
            var str = "";
            for (var i = 0; i < res.records.length; i++) {
                str += '<div class="onework"><div style="display: none" class="inum">'+i+'</div><div class="topwork"><img src="http://' + res.records[i].picUrl + '" class="songimg"><div class="zaninfo"><div class="smallinfo" style="padding-left: 0.05rem"><img src="img/show.png" alt=""> ' + res.records[i].playCount + '</div><div class="smallinfo"><img src="img/like.png" alt=""> ' + res.records[i].likesCount + '</div></div></div><div class="botwork">' + res.records[i].song_info.name + '</div></div>'
            }
            $("#workInfo").append(str);
            toPlay();

        },
        error: function (res) {

        }
    });
}

//点击作品
$("#works").on("click", function () {
    $("#works").addClass("cursty");
    $("#colltxt").removeClass("cursty");
    $("#workInfo").show();
    $("#collection").hide();
})
//点击收藏
$("#colltxt").on("click", function () {
    $("#colltxt").addClass("cursty");
    $("#works").removeClass("cursty");
    $("#collection").show();
    $("#workInfo").hide();
})

//判断进来的事件
var bef = window.location.href.split("?")[1];
if (bef == "his") {
    $("title").html("TA的主页");
    $("#footer").hide();
    $("body").css("padding-top", 0);
    $("#calfollow").show();
    var uid = sessionStorage.getItem("uid");
    var UserInfo = JSON.parse(sessionStorage.getItem("UserInfo"));
    $("#headimg").attr("src", UserInfo[1]);
    $("#headright").text(UserInfo[0])
    getWorks(uid)
} else if (bef == "my") {
    $("title").html("我的主页");
    $("#footer").show();
} else {
    $("body").css("padding-top", 0);
}

//点击推荐
$("#recommend").on("click", function () {
    window.location.href = "playMusic.html";
})

//点击粉丝跳转TA的粉丝
$("#fans").on("click", function () {
    var curTitle = $("title").text()
    if (curTitle == "TA的主页") {
        window.location.href = "fans.html?TAfans";
    } else if (curTitle == "我的主页") {
        window.location.href = "fans.html?Myfans";
    }
})

//点击关注跳转TA的关注
$("#focus").on("click", function () {
    var curTitle = $("title").text()
    if (curTitle == "TA的主页") {
        window.location.href = "fans.html?TAfocus";
    } else if (curTitle == "我的主页") {
        window.location.href = "fans.html?Myfocus";
    }
})

//点击歌曲跳转播放页面
function toPlay() {
    $(".onework").on("click", function () {
        var mark=$(this).children(".inum").text();
        window.location.href = "playMusic.html?mark="+mark+"&uid="+sessionStorage.getItem("uid");
    })
}


//关注/取消关注
$("#calfollow").on("click", function () {
    var followTxt = $("#calfollow").text();
    if (followTxt == "取消关注") {
        $("#calfollow").text("关注");
        $("#calfollow").css("background", "#6e93c9");
    } else if (followTxt == "关注") {
        $("#calfollow").text("取消关注");
        $("#calfollow").css("background", "#7f7f81");
    }
})






